package com.dao.impl;

import com.dao.InstitutyDao;
import com.entry.Instituty;
import com.util.DBHelper;

import java.util.ArrayList;

public class InstitutyDaoImpl implements InstitutyDao {

    private DBHelper dbHelper = new DBHelper();
    @Override
    public ArrayList selectQuery(Instituty instituty) {
        StringBuilder sql = new StringBuilder("select * from instituty where 1=1 ");
        ArrayList list = new ArrayList();
        if (instituty.getName()!=null){
            sql.append(" and name=? ");
            list.add(instituty.getName());
        }
        if(instituty.getInstituty_id()!=null){
            sql.append(" and instituty_id=? ");
            list.add(instituty.getInstituty_id());
        }
        return dbHelper.selectinfo(sql.toString(),Instituty.class,list.toArray());
    }

    @Override
    public ArrayList selectAll() {
        String sql="SELECT * FROM instituty";
        ArrayList<Instituty> list=dbHelper.selectinfo(sql,Instituty.class);
        return list;
    }
}
